package com.han.adbconnect.utils;


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class NetworkUtils {
    public static final String IP_DEFAULT = "0.0.0.0";

    public static final String NET_TYPE_MOBILE = "MOBILE";

    public static final String NET_TYPE_NO_NETWORK = "no_network";

    public static final String NET_TYPE_WIFI = "WIFI";

    private Context mContext = null;

    public NetworkUtils(Context paramContext) {
        this.mContext = paramContext;
    }

    public static int getConnectType(Context paramContext) {
        NetworkInfo networkInfo = ((ConnectivityManager)paramContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        int i = -1;
        if (networkInfo != null)
            i = networkInfo.getType();
        return i;
    }

    public static String getIPAddress() {
        try {
            Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
            while (enumeration.hasMoreElements()) {
                Enumeration<InetAddress> enumeration1 = ((NetworkInterface)enumeration.nextElement()).getInetAddresses();
                while (enumeration1.hasMoreElements()) {
                    InetAddress inetAddress = enumeration1.nextElement();
                    if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress())
                        return inetAddress.getHostAddress();
                }
            }
            return "0.0.0.0";
        } catch (SocketException socketException) {
            return "0.0.0.0";
        }
    }

    public static String getNetTypeName(int paramInt) {
        switch (paramInt) {
            default:
                return "unknown";
            case 0:
                return "unknown";
            case 1:
                return "GPRS";
            case 2:
                return "EDGE";
            case 3:
                return "UMTS";
            case 4:
                return "CDMA: Either IS95A or IS95B";
            case 5:
                return "EVDO revision 0";
            case 6:
                return "EVDO revision A";
            case 7:
                return "1xRTT";
            case 8:
                return "HSDPA";
            case 9:
                return "HSUPA";
            case 10:
                return "HSPA";
            case 11:
                return "iDen";
            case 12:
                return "EVDO revision B";
            case 13:
                return "LTE";
            case 14:
                return "eHRPD";
            case 15:
                break;
        }
        return "HSPA+";
    }

    public static boolean isConnectInternet(Context paramContext) {
        NetworkInfo networkInfo = ((ConnectivityManager)paramContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        return (networkInfo != null) ? networkInfo.isAvailable() : false;
    }

    public String getConnTypeName() {
        NetworkInfo networkInfo = ((ConnectivityManager)this.mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        return (networkInfo == null) ? "no_network" : networkInfo.getTypeName();
    }
}

